import 'package:flutter/material.dart';
import '../../resources/colors.dart';
import '../widget.dart';

class MyImageButton extends StatelessWidget {
  final String title; //名称
  final bool svgIcon; //是否是svg图片
  final String imagePath; //图片路径
  final Color? bgColor;
  final double size;
  final double gap;
  final double paddingGap;
  final Color? imageColor;
  final double fontSize;
  final Color? fontColor;
  final FontWeight fontWeight;

  final VoidCallback? onPressed;

  const MyImageButton({
    super.key,
    required this.title,
    required this.imagePath,
    this.svgIcon = false,
    this.onPressed,
    this.bgColor,
    this.size = 70,
    this.gap = 4,
    this.paddingGap = 8,
    this.imageColor,
    this.fontSize = 13,
    this.fontWeight = FontWeight.normal,
    this.fontColor,
  });

  @override
  Widget build(BuildContext context) {
    final imageSize = size - (paddingGap * 2) - gap - fontSize - 6;

    return MyInkWell(
      onTap: onPressed,
      child: Container(
        width: size,
        height: size,
        alignment: Alignment.center,
        padding: EdgeInsets.all(paddingGap),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(12),
          color: bgColor ?? Colors.white,
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Container(
              width: imageSize,
              height: imageSize,
              alignment: Alignment.center,
              child: svgIcon
                  ? MySvg(
                      imagePath,
                      color: imageColor,
                    )
                  : MyImage(imagePath, color: imageColor),
            ),
            SizedBox(height: gap),
            MyText(
              title,
              size: fontSize,
              color: fontColor ?? JmColors.textColor,
              weight: fontWeight,
            ),
          ],
        ),
      ),
    );
  }
}
